﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Student.EFCore
{
    [ConnectionStringName("Default")]
    public class StudentDbContext : AbpDbContext<StudentDbContext>,IAbpEfCoreDbContext
    {
        public DbSet<Domain.Entities.Student> Students { get; set; }

        public StudentDbContext(DbContextOptions<StudentDbContext> options) : base(options)
        {

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<Domain.Entities.Student>(b =>
            {
                b.ToTable<Domain.Entities.Student>("abcd_student");
                // 如果不加这个，那审计用的字段就没有文字说明
                // 比如：创建人 创建时间 修改人 修改时间 删除标记 删除人 删除时间
                b.ConfigureByConvention();

                b.Property(x => x.Name).HasMaxLength(20).HasComment("名字");
                b.Property(x => x.BirthDate).HasComment("出生日期");
            });
        }
    }
}
